package com.yunquan.ohana.ui.calendar.task.adapter

import android.graphics.Color
import android.graphics.Paint
import androidx.databinding.ViewDataBinding
import com.yunquan.ohana.R
import com.yunquan.ohana.databinding.ItemTaskListBinding
import com.yunquan.ohana.ui.calendar.task.TaskItemViewModel
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter

class TaskAdapter : BindingRecyclerViewAdapter<TaskItemViewModel>() {

    override fun onBindBinding(binding: ViewDataBinding, variableId: Int, layoutRes: Int, position: Int, item: TaskItemViewModel?) {
        super.onBindBinding(binding, variableId, layoutRes, position, item)
        if (binding is ItemTaskListBinding) {
            val resources = binding.root.resources
            binding.swipeDeleteLayout.closeAllOpenedMenus()

            binding.vOut.helper.cornerRadius = resources.getDimensionPixelSize(R.dimen.dp_16).toFloat()
            binding.clInner.helper.cornerRadius = resources.getDimensionPixelSize(R.dimen.dp_16).toFloat()

            if (item?.status?.get() == true) {
                binding.tvContent.setTextColor(binding.root.context.resources.getColor(R.color.c_ff8b8b8b))
                binding.tvContent.paintFlags = binding.tvContent.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
                binding.vOut.helper.backgroundColorNormal = binding.vOut.resources.getColor(R.color.c_ff8b8b8b)
                binding.clInner.helper.backgroundColorNormal = binding.clInner.resources.getColor(R.color.c_f3)
            } else {
                binding.tvContent.setTextColor(binding.root.context.resources.getColor(R.color.c_20))
                binding.tvContent.paintFlags = binding.tvContent.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
                binding.vOut.helper.backgroundColorNormal = item!!.inner.get()!!
                binding.clInner.helper.backgroundColorNormal = item.outer.get()!!
            }
        }
    }
}